<template>
  <div class="container">
    <div v-if="!isSuccess" class="form-wrapper">
      <h1 class="title">用户登记</h1>
      <form @submit.prevent="handleSubmit" class="form">
        <div class="form-group">
          <label for="name" class="label">姓名：</label>
          <input
            type="text"
            id="name"
            v-model.trim="name"
            placeholder="请输入您的姓名"
            required
            autofocus
            class="input"
          />
        </div>
        <button type="submit" class="submit-btn" :disabled="isSubmitting">
          {{ isSubmitting ? '提交中...' : '立即登记' }}
        </button>
      </form>
    </div>

    <div v-else class="success-wrapper">
      <svg class="checkmark" viewBox="0 0 52 52">
        <circle class="checkmark-circle" cx="26" cy="26" r="25"/>
        <path class="checkmark-check" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
      </svg>
      <h2 class="success-title">登记成功！</h2>
      <p class="success-message">感谢您的登记，{{ name }}！</p>
      <button @click="resetForm" class="reset-btn">返回登记</button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const name = ref('');
const isSuccess = ref(false);
const isSubmitting = ref(false);

const handleSubmit = async () => {
  if (!name.value) return;
  
  isSubmitting.value = true;
  
  try {
    // 模拟API请求
    await new Promise(resolve => setTimeout(resolve, 1500));
    
    isSuccess.value = true;
    isSubmitting.value = false;
  } catch (error) {
    alert('提交失败，请稍后再试');
    isSubmitting.value = false;
  }
};

const resetForm = () => {
  name.value = '';
  isSuccess.value = false;
};
</script>

<style>
/* 基础样式 */
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

/* 表单样式 */
.form-wrapper {
  background: white;
  border-radius: 16px;
  padding: 32px 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 480px;
}

.title {
  font-size: 24px;
  margin-bottom: 24px;
  text-align: center;
  color: #2c3e50;
}

.form-group {
  margin-bottom: 24px;
}

.label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #34495e;
}

.input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #ecf0f1;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s ease;
}

.input:focus {
  border-color: #3498db;
  outline: none;
}

.submit-btn {
  width: 100%;
  padding: 14px;
  background: #3498db;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
}

.submit-btn:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
}

/* 成功页面样式 */
.success-wrapper {
  text-align: center;
}

.checkmark {
  width: 120px;
  height: 120px;
  margin: 0 auto 24px;
}

.checkmark-circle {
  fill: none;
  stroke: #2ecc71;
  stroke-width: 4;
  stroke-linecap: round;
  animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark-check {
  fill: none;
  stroke: white;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 36;
  stroke-dashoffset: 36;
  animation: check 0.3s 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

@keyframes stroke {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes check {
  to {
    stroke-dashoffset: 0;
  }
}

.success-title {
  font-size: 24px;
  color: #2ecc71;
  margin-bottom: 12px;
}

.success-message {
  font-size: 16px;
  color: #34495e;
  margin-bottom: 24px;
}

.reset-btn {
  padding: 12px 24px;
  background: #3498db;
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
}

.reset-btn:hover {
  background: #2980b9;
}

/* 响应式优化 */
@media (max-width: 480px) {
  .title {
    font-size: 22px;
  }
  
  .input {
    font-size: 16px;
    padding: 12px 14px;
  }
  
  .submit-btn {
    font-size: 16px;
  }
}
</style>